
package tester;

import java.io.*;
import org.apache.log4j.*;

import codeformatter.Formatter;

import exceptions.ReadStreamException;
import exceptions.WriteStreamException;
import exceptions.WrongBracketAmountException;

import params.ParamsController;

public class Tester{
    public static Logger createLogger(String fileName, Level lvl) throws IOException{
        Logger logger = Logger.getLogger("codeformatter.tester");
        logger.setLevel(lvl);
        PatternLayout layout = new PatternLayout("%r [%t] %-5p %c{2} %x - %m%n");
        FileAppender fa = new FileAppender(layout, fileName, true);
        logger.addAppender(fa); 
        
        return logger;
    }
    public static void main(String[] args) {

        Logger logger = null;
        try{
            ParamsController.fillParameters("formatterparams.property");
            logger = createLogger("logfile.txt", Level.ERROR);      
            Formatter f = new Formatter();
            InputStream is = new FileInputStream("input.txt");
            OutputStream os = new FileOutputStream("output.txt");
            f.format(is, os);
            is.close();
            os.close();
        }
        catch(ReadStreamException e){
            logger.error(e);
        }
        catch(WriteStreamException e){
            logger.error(e);
        }
        catch(WrongBracketAmountException e){
            logger.error(e);
        }
        catch(FileNotFoundException e){
            logger.error(e);
        }
        catch(IOException e){
            logger.error(e);
        }
    }
}
